<?php
/**
 * Created by PhpStorm.
 * User: 热心观众
 * Date: 2018/9/27
 * Time: 11:32
 */

namespace app\admin\controller;


use think\Db;
use think\Controller;//引入系统控制器类
//use \app\index\model\User;//导入user模块


class User extends AdminController
{
//    会员列表
    public function UserList()
    {
        $search = input('search');
        $ulist = Db::table('zz_user')
                ->where('zz_name','like','%'.$search.'%')
                ->order('zz_id','asc')
                ->paginate(5);
        $total = count(Db::table('zz_user')->field('zz_id')->select());
//        dump($total);die;
        //dump($ulist);die;
        
        return view('user/user-list',[
            'ulist'=>$ulist,
            'total'=>$total
        ]);
    }
//    添加会员
    public function UserAdd()
    {
        return view('user/user-add');
    }
    
//    执行添加会员
    public function DoAdd()
    {   $tel = input('tel');
        $email= input('email');
        $name = input('name');
        $pass = input('pass');
        $data = [];
        $data['zz_tel']=$tel;
        $data['zz_email']=$email;
        $data['zz_name']=$name;
        $data['zz_pass']=$pass;

        Db::table('zz_user')->insert($data);
        $info=[];
        $info['status']=1;
        return json($info);
    }
//    编辑会员页面
    public function UserEdit($id)
    {
        $ulist = Db::table('zz_user')->where('zz_id',$id)->find();
//        dump($ulist);die;
        return view('user/user-edit',['ulist'=>$ulist]);
    }
//    执行修改用户信息
    public function DoEdit()
    {

        $id = input('id', '', 'int');
        $tel= input('tel');
        $email= input('email');
        $name = input('name');
        $pass = input('pass');
        $data = [];
        $data['zz_tel']=$tel;
        $data['zz_email']=$email;
        $data['zz_name']=$name;
        $data['zz_pass']=$pass;


        Db::table('zz_user')->where('zz_id',$id)->update($data);
        $info=[];
        $info['status']=1;
        return json($info);


    }

//    执行停用会员
    public function DoDel()
    {
        $id = input('id');
        $status = input('status');

        $data = array();
        if ($status == 1){
            $data['zz_status'] = 2;
        }else{
            $data['zz_status'] = 1;
        }

        Db::table('zz_user')->where('zz_id',$id)->update($data);


        $info=[];
        $info['status']=1;
        return json($info);
    }




}